package com.woniu1.jdkproxy;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

public class JdkProxyFactory {
    public Object createProxyObject(Object obj){
        Object o = Proxy.newProxyInstance(obj.getClass().getClassLoader(), obj.getClass().getInterfaces(), new InvocationHandler() {
            @Override
            public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
                //前置增强
                System.out.println("怪兽1");
                //通过放射
                Object invoke = method.invoke(obj, args);

                //后置增强
                System.out.println("怪兽1被打败");
                return invoke;
            }
        });
        return o;
    }
}
